package com.blb.demo4;

import com.blb.demo2.ReadRunnable;
import com.blb.demo2.WriteRunnable;

import java.io.*;
import java.net.Socket;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class FileClient {


    public void connect(String ip, int port) {


        try {
            Socket socket = new Socket(ip, port);
            String fileAddr = "C:\\Users\\廉壮\\IdeaProjects\\test\\_20230720_day04network\\src\\com\\blb\\demo4\\images\\1.png";
            FileInputStream fileInputStream = new FileInputStream(new File(fileAddr));
            OutputStream outputStream = socket.getOutputStream();
            byte[] data = new byte[1024];
            while (true) {
                int len = fileInputStream.read(data);
                if (len == -1) {
                    break;
                }
                outputStream.write(data);
                outputStream.flush();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        new FileClient().connect("192.168.1.111",8888);
    }

}
